import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:app_updater/app_updater.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      appUpdater.startDownload('https://ip4052520118.mobgslb.tbcache.com/fs08/2020/11/09/10/106_e5160ced9ee73702d305631fc0189347.apk?yingid=wdj_web&fname=%E7%99%BE%E5%BA%A6&productid=2011&pos=wdj_web%2Fdetail_normal_dl%2F0&appid=39899&packageid=400951494&apprd=39899&iconUrl=http%3A%2F%2Fandroid-artworks.25pp.com%2Ffs08%2F2020%2F11%2F09%2F1%2F110_c6633421f9f8b194be887732a74cdc8d_con.png&pkg=com.baidu.searchbox&did=841ba0b46900b0b2fa0604baaba97e88&vcode=101451136&md5=9d794fddc995f2105ca5203cf94f0d1e&ali_redirect_domain=alissl.ucdl.pp.uc.cn&ali_redirect_ex_ftag=6045eb2736a76535d321d4158af91e9c8fb6dec141f85f3b&ali_redirect_ex_tmining_ts=1605252483&ali_redirect_ex_tmining_expire=3600&ali_redirect_ex_hot=100', (data){});
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Running on: $_platformVersion\n'),
        ),
      ),
    );
  }
}
